package com.dingshi.security.view;


import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager.LayoutParams;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.dingshi.security.R;

public class NightDialog extends Dialog  implements OnClickListener{

	private Context context;


	private TextView countdownText;

	private Button btn_normal;

	private Button btn_unnormal;


	public OnButtonClickListener buttonClickListener;

	public NightDialog(Context context, boolean cancelable, OnCancelListener cancelListener) {
		super(context, cancelable, cancelListener);
		init(context, null);
	}

	public NightDialog(Context context, int theme) {
		super(context, theme);
		init(context, null);
	}

	public NightDialog(Context context, OnButtonClickListener buttonClickListener) {
		super(context);
		init(context, buttonClickListener);
	}


	private void init(Context context, OnButtonClickListener buttonClickListener) {
		this.context = context;
		this.buttonClickListener = buttonClickListener;
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		
//		linearLayout.setBackgroundResource(R.drawable.bg_toast);
		LinearLayout linearLayout = (LinearLayout) getLayoutInflater().inflate(R.layout.night_dialog, null);
		linearLayout.getBackground().setAlpha(127);
		linearLayout.setGravity(Gravity.CENTER);
		setContentView(linearLayout, new ViewGroup.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
		
		countdownText = (TextView)linearLayout.findViewById(R.id.countdown_text);
		btn_normal = (Button)linearLayout.findViewById(R.id.btn_normal);
		btn_unnormal = (Button)linearLayout.findViewById(R.id.btn_unnormal);
		
		if(btn_normal!=null) {
			btn_normal.setOnClickListener(this);
		}
		if(btn_unnormal!=null) {
			btn_unnormal.setOnClickListener(this);
		}
	}

	public TextView getCountDown() {
		return countdownText;
	}

	public Button getNormalButton() {
		return btn_normal;
	}
	public Button getUnNormalButton() {
		return btn_unnormal;
	}

	@Override
	public void onClick(View v) {
		if (buttonClickListener == null) {
			return;
		}
		switch (v.getId()) {
		case R.id.btn_normal:
			buttonClickListener.onOkButtonClicked(this);
			break;
		case R.id.btn_unnormal:
			buttonClickListener.onCancleButtonClicked(this);
			break;
		}
	}

	
	public interface OnButtonClickListener {
		void onOkButtonClicked(NightDialog dialog);

		void onCancleButtonClicked(NightDialog dialog);
	}
}
